<div class="QuanLyMenu">
	<div class="Phai">
		<div class="ChuDeDetail">
			<?php
				include_once "../classes/menu_bs.php";
				include_once "../classes/submenu_bs.php";
				include_once "../classes/thuvienham.php";
				if(!IsAdmin())
					header("Location: index.php");
				$menu = new menu_bs();
				$data_menu = $menu->LayDanhSach();
				$MaxIndex = $menu->MaxIndex();
			?>
			<h4 align="center">Quản lý Menu</h4>
			<table class='DSInProfile' width="90%">
				<tr>
					<th>STT</th>
					<th>Mã Menu</th>
					<th>Tên Menu</th>
					<th>Mô tả</th>
					<th>Loại Menu</th>
					<th>Sub Menu</th>
					<th>Trạng thái</th>
					<th>Vị trí</th>
				</tr>
				<?php
					$id_m = "M";
					for($i = 0; $i < count($data_menu); $i++)
					{
						$TrangThai = $data_menu[$i]['TrangThai'] == 0 ? "Chưa kích hoạt" : "Đang hoạt động";
						switch((int)$data_menu[$i]['MaLoaiMenu'])
						{
							case 1:
								$LoaiMN = "Danh sách bài viết";
								break;
							case 2:
								$LoaiMN = "Bài viết";
								break;
							case 3:
								$LoaiMN = "Liên kết ngoài";
								break;
							default:
								$LoaiMN = "Khác";
								break;
						}
						$submenu = new submenu_bs();
						$submenu->SetMaMenu($data_menu[$i]['MaMenu']);
						$data_submenu = $submenu->LayDanhSach();
						$count_submenu = ($data_submenu == null) ? "-" : count($data_submenu);
						
						$LinkUpIndex = "index.php?actionad=menu_index_up&id=" . $data_menu[$i]['MaMenu'] . "&pin=" . $data_menu[$i]['PIN'];
						$LinkDownIndex = "index.php?actionad=menu_index_down&id=" . $data_menu[$i]['MaMenu'] . "&pin=" . $data_menu[$i]['PIN'];
						
						$linkSub = $data_menu[$i]['TenMenu'];
						echo '<tr id="'. $id_m . $data_menu[$i]['MaMenu'] .'">';
							echo '<td width="40px" align="center"><b>' . ($i + 1) . '</b></td>';
							echo '<td width="50px" align="center">' . $data_menu[$i]['MaMenu'] . '</td>';
							echo '<td width="150px">' . $linkSub . '</td>';
							echo '<td>' . $data_menu[$i]['MoTa'] . '</td>';
							echo '<td width="60px" align="center" title="' . $LoaiMN . '">' . ($data_menu[$i]['MaLoaiMenu'] == 1 ? '<img src="../data/list_article.png" />' : '') . '</td>';
							echo '<td align="center">' . $count_submenu . '</td>';
							echo '<td width="50px" align="center"><a href="index.php?actionad=menu_toggle&id=' . $data_menu[$i]['MaMenu'] . '&pin=' . $data_menu[$i]['PIN'] . '">' . ($data_menu[$i]['TrangThai'] == 1 ? '<img src="../data/xuatban.png" />' : '<img src="../data/xuatban_no.png" />') . '</a></td>';
							echo '<td width="80px" align="center">' . (($data_menu[$i]['Index'] != $MaxIndex) ? '<a href="' . $LinkDownIndex . '"><img src="../data/godown.png" /></a> ' : '<img src="../data/none.png" /> ') . $data_menu[$i]['Index'] . (($data_menu[$i]['Index'] != 1) ? ' <a href="' . $LinkUpIndex . '"><img src="../data/goup.png" /></a>' : ' <img src="../data/none.png" />') .'</td>';
						echo '</tr>';
					}
				?>
			</table>
		</div>
		
		<?php
			$id_sm = "SM";
			for($h = 3; $h <= 10; $h++)
			{
				
		?>
		<div id="<?php echo $id_sm . $h; ?>" hidden="true">
			<?php
				include_once "../classes/menu_bs.php";
				include_once "../classes/submenu_bs.php";
				include_once "../classes/thuvienham.php";
				
				if(true)
				{
					$MaMenu = $h;
					
					$menu= new menu_bs();
					$menu->SetMaMenu($MaMenu);
					$d_menu = $menu->LayDanhSach();
					
					$submenu = new submenu_bs();
					$submenu->SetMaMenu($MaMenu);
					$data_submenu = $submenu->LayDanhSach();
					$MaxIndex2 = $submenu->MaxIndex();
					echo '<h4 align="center">Danh sách submenu của "' . $d_menu[0]['TenMenu'] . '"</h4>';
					echo '<table class="DSInProfile" width="90%">';
						echo '<tr>';
							echo '<th>STT</th>';
							echo '<th>Mã Menu</th>';
							echo '<th>Tên Menu</th>';
							echo '<th>Mô tả</th>';
							echo '<th>Loại Menu</th>';
							echo '<th>Trạng thái</th>';
							echo '<th>Vị trí</th>';
						echo '</tr>';
					if($data_submenu != null)
					{
						for($j = 0; $j < count($data_submenu); $j++)
						{
							$TrangThai = $data_submenu[$j]['TrangThai'] == 0 ? "Chưa kích hoạt" : "Đang hoạt động";
							switch($data_submenu[$j]['MaLoaiMenu'])
							{
								case 1:
									$LoaiMN = "Danh sách bài viết";
									break;
								case 2:
									$LoaiMN = "Bài viết";
									break;
								case 3:
									$LoaiMN = "Liên kết ngoài";
									break;
							}
							echo '<tr >';
								echo '<td width="40px" align="center">' . ($j + 1) . '</td>';
								echo '<td width="50px" align="center">' . $data_submenu[$j]['MaSubMenu'] . '</td>';
								echo '<td width="150px">' . $data_submenu[$j]['TenSubMenu'] . '</td>';
								echo '<td>' . $data_submenu[$j]['MoTa'] . '</td>';
								echo '<td width="60px" align="center" title="' . $LoaiMN . '">' . ($data_submenu[$j]['MaLoaiMenu'] == 1 ? '<img src="../data/list_article.png" />' : '') . '</td>';
								echo '<td width="50px" align="center"><a href="index.php?actionad=submenu_toggle&id=' . $data_submenu[$j]['MaSubMenu'] . '&pin=' . $data_submenu[$j]['PIN'] . '">' . ($data_submenu[$j]['TrangThai'] == 1 ? '<img src="../data/xuatban2.png" />' : '<img src="../data/xuatban_no.png" />') . '</a></td>';
								echo '<td width="80px" align="center">' . ($d_menu[0]['Index']) . '.' . $data_submenu[$j]['Index'] . '</td>';
							echo '</tr>';
						}
					}
					else
					{
						echo '<tr >';
							echo '<td align="center" colspan="7">Mục này không có Submenu</td>';
						echo '</tr>';
					}
					echo '</table>';
				}
				else
				{
					QuayVeTrangTruoc();
				}
			?>
		</div>
		
		<?php
			}
		?>
		
	</div>
</div>

<script>
	var options = {};
	options = { percent: 100 };
	options = { to: { width: 280, height: 185 } };
	$(document).ready(function(){
		$("#SM3").hide();
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').hide();
	});
	
	$('#M3').click(function(){
		$("#SM3").show("blind");
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').hide();
	});
	$('#M4').click(function(){
		$('#SM3').hide();
		$('#SM4').show("blind");
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').hide();
	});
	$('#M5').click(function(){
		$('#SM3').hide();
		$('#SM4').hide();
		$('#SM5').show("blind");
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').hide();
	});
	$('#M6').click(function(){
		$('#SM3').hide();
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').show("blind");
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').hide();
	});
	$('#M7').click(function(){
		$('#SM3').hide();
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').show("blind");
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').hide();
	});
	$('#M8').click(function(){
		$('#SM3').hide();
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').show("blind");
		$('#SM9').hide();
		$('#SM10').hide();
	});
	$('#M9').click(function(){
		$('#SM3').hide();
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').show("blind");
		$('#SM10').hide();
	});
	$('#M10').click(function(){
		$('#SM3').hide();
		$('#SM4').hide();
		$('#SM5').hide();
		$('#SM6').hide();
		$('#SM7').hide();
		$('#SM8').hide();
		$('#SM9').hide();
		$('#SM10').show("blind");
	});
	
</script>